using Bridge.Html5;
using Bridge.Test.NUnit;

namespace Bridge.ClientTest.Batch3.BridgeIssues
{
    /// <summary>
    /// The test here consists in ensuring expressions involving Bridge.Html5's
    /// Typed Array constants would always reference the browser's values.
    /// </summary>
    [TestFixture(TestNameFormat = "#1373 - {0}")]
    public class Bridge1373
    {
        [Test]
        public static void TypedArraysConstantsInExpressions()
        {
            Assert.AreEqual(8, Float32Array.BYTES_PER_ELEMENT * 2, "2x Float32Array's bytes per element is 8.");
            Assert.AreEqual(16, Float64Array.BYTES_PER_ELEMENT * 2, "2x Float64Array's bytes per element is 16.");
            Assert.AreEqual(4, Int16Array.BYTES_PER_ELEMENT * 2, "2x Int16Array's bytes per element is 4.");
            Assert.AreEqual(8, Int32Array.BYTES_PER_ELEMENT * 2, "2x Int32Array's bytes per element is 8.");
            Assert.AreEqual(2, Int8Array.BYTES_PER_ELEMENT * 2, "2x Int8Array's bytes per element is 2.");
            Assert.AreEqual(4, Uint16Array.BYTES_PER_ELEMENT * 2, "2x Uint16Array's bytes per element is 4.");
            Assert.AreEqual(8, Uint32Array.BYTES_PER_ELEMENT * 2, "2x Uint32Array's bytes per element is 8.");
            Assert.AreEqual(2, Uint8Array.BYTES_PER_ELEMENT * 2, "2x Uint8Array's bytes per element is 2.");
            Assert.AreEqual(2, Uint8ClampedArray.BYTES_PER_ELEMENT * 2, "2x Uint8ClampedArray's bytes per element is 2.");
        }
    }
}

/*
 * The repetitive test was generated by this script:
#!/bin/bash
_ifs="${IFS}"

IFS=$'\n' files=($(ls Html5/TypedArray/*Array.cs)) IFS="${_ifs}"

for file in "${files[@]}"; do
 clsnme="${file##* /}" # remove whitespace (would close C# comment block)
 clsnme="${clsnme%.*}"
 bpeval="$(egrep "element size\. [0-9]+" "${file}" | sed -E "s/^.* element size\. ([0 - 9]+) .*\$/\1/g")"
 bpevalx2=$(( 10#${bpeval} * 2 ))
 echo "            Assert.AreEqual(${bpevalx2}, ${clsnme}.BYTES_PER_ELEMENT * 2, \"2x ${clsnme}'s bytes per element is ${bpevalx2}.\");"
done
 */